# Info from v.mod
NAME    := $(shell awk '/name:/ {print $$2}' v.mod | sed s/\'//g)
DESC	:= $(shell awk '/description:/ {sub($$1 FS,""); print }' v.mod | sed s/\'//g)
VERSION := $(shell awk '/version:/ {print $$2}' v.mod | sed s/\'//g)
LICENSE := $(shell awk '/license:/ {print $$2}' v.mod | sed s/\'//g)
DEPS	:= $(shell awk '/dependencies:/ {print $$2}' v.mod | sed s/\'//g)


# Compiler and flags
VDIR	   := ~/.local/bin/v
V   	   := $(VDIR)/v 
V_FLAGS    := #-b native
V.JS 	   := $(V) -b js_browser
V.JS_FLAGS :=

# Directories and files
PROJROOT := $(shell pwd)
OUTDIR	 := $(PROJROOT)/output
BINDIR   := $(OUTDIR)/bin
LIBDIR   := $(OUTDIR)/lib 
JUNK	 := $(shell cat .gitignore)

# Adjusting for build type
BUILD_TYPE := Debug
ifeq ($(BUILD_TYPE), Release)
	V_FLAGS += -prod
else
	V_FLAGS += -cg
endif

all: logo $(V) $(BINDIR)/site
rebuild: clean all

logo:
	@figlet $(NAME)
	@echo "Version: $(VERSION)"
	@echo "License: $(LICENSE)"
# @echo "Description: $(DESC)"
	@printf "\n"

clean:
	rm -rf $(JUNK)

run: $(BINDIR)/site
	$(BINDIR)/site

$(V):
	mkdir -p $(VDIR)
	git clone https://github.com/vlang/v $(VDIR)
	make -C $(VDIR)
	$(VDIR)/v install

$(OUTDIR):
	mkdir -p $(OUTDIR)

$(BINDIR): $(OUTDIR)
	mkdir -p $(BINDIR)

$(LIBDIR): $(OUTDIR)
	mkdir -p $(LIBDIR)

$(BINDIR)/site: $(BINDIR)
	$(V) $(V_FLAGS) -o $(BINDIR)/site src/ 